Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DnD for mobile #699

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Conversation

luckylionheart
Copy link

No description provided.

@luckylionheart luckylionheart changed the title WIP: add touchstart, touchend, touchmove event for mobile drag and drop Add touchstart, touchend, touchmove event for mobile drag and drop Sep 23, 2024
@blokhin
Copy link

blokhin commented Sep 23, 2024

fixes #456

@luckylionheart
Copy link
Author

@blokhin
http://85.208.108.223:9080/hyoo/mol/-/test.html#!section=demos
can you check this link for live test?

@blokhin
Copy link

blokhin commented Oct 8, 2024

@luckylionheart what is initial_task_index and why it is needed here?

@luckylionheart
Copy link
Author

@blokhin
yes, I think so. It's a drag module, initial_task_index will be deal in demo.view.ts file. I was confused. I will fix it.

@blokhin
Copy link

blokhin commented Oct 19, 2024

@luckylionheart ready now?

@luckylionheart
Copy link
Author

http://85.208.108.223:9080/hyoo/mol/-/test.html#!section=demos/demo=mol_drag_demo
@blokhin I updated the project. but I think it's not complete yet. Please kindly check above url.

@luckylionheart
Copy link
Author

@blokhin did you check the live server?

@luckylionheart
Copy link
Author

@blokhin I add the new commit. Please kindly check it.
live test URL: http://85.208.108.223:9080/hyoo/mol/-/test.html#!section=demos/demo=mol_drag_demo

@blokhin
Copy link

blokhin commented Nov 11, 2024

OK, now it works in iOS 🎉

Copy link
Member

@stan-donarise stan-donarise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some comments, but I still think we should implement this with dragevent, without touchevent, since it will be much simpler.

Emulating this with touchevent is also ok, but in this case we will need to adapt $mol_drop for this emulation.

Comment on lines 6 to 8
private dragged_task: HTMLElement | null = null;
private initial_task_index: number | null = null;
private draggedOverElem: HTMLElement | null = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no info about the dragged element, this is the work for $mol_drop. The new position of the passed element must be determined by $mol_drop. $mol_drag don't move element before drop.

If we want a component that immediately changes the position of elements when the pointer is moved, it will be a different component, not $mol_drag.

);

if (draggedOverIndex !== this.initial_task_index) {
parent!.insertBefore(this.dragged_task!, draggedOverElem);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't make any direct changes to the DOM. Instead, we set values ​​for props and the components render the DOM.


this.dragImageElem.style.position = "absolute";
this.dragImageElem.style.pointerEvents = "none";
this.dragImageElem.style.zIndex = "9999";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dragImageElem should be located in drag.view.tree.
Static styles of it in drag.view.css.ts, dynamic styles in view.tree style *
Name should be in snake_case.

Also I suggest not to clone the dragged element, it may be large and this may cause glitches since the cloned elements will have the same ids.
Instead I suggest making Drag_label $mol_paragraph which will just be the title of the dragged element

moveDragImage(x: number, y: number) {
if (this.dragImageElem) {
this.dragImageElem.style.left = `${x + 50}px`;
this.dragImageElem.style.top = `${y + 50}px`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-50, -50 would be better, I can't see the object under my finger :)

if (this.draggedOverElem) {
if (
this.draggedOverElem.id ==
"$hyoo_mol.Root(0).Demos().Widget('$mol_drag_demo').Trash()"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only work for $hyoo_mol.Root(0).Demos().Widget('$mol_drag_demo').Trash().

Anyway, this should be handled in $mol_drop, not $mol_drag.

@luckylionheart
Copy link
Author

@stan-donarise thanks so much for your feedback. I will fix it according to your comment. Thanks

@luckylionheart
Copy link
Author

@blokhin
http://85.208.108.223:9080/hyoo/mol/-/test.html#!section=demos/demo=mol_drag_demo
Please kindly check the live server, Today, I discuss with @stan-donarise and continued the work to use drag event.
Using Dragevent, I did the drag and drop on mobile.

@blokhin
Copy link

blokhin commented Nov 14, 2024

OK, I confirm it works now once again. Although a previous version demonstrated a smoother and intuitively easier drag and drop on iOS. Unlike now, one did not have to press hard on draggable, and even a scroll-alike touching worked flawlessly.

@blokhin
Copy link

blokhin commented Nov 14, 2024

@luckylionheart but I cannot see any changes in drag.view.tree and drag.view.ts

@luckylionheart
Copy link
Author

@blokhin yes, because, we used drag event. drag event is already defined. but need to some change for mobile dnd.

drag/demo/demo.view.ts Outdated Show resolved Hide resolved
@luckylionheart luckylionheart changed the title Add touchstart, touchend, touchmove event for mobile drag and drop Add DnD for mobile Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants